package consul

import (
	"fmt"
	"github.com/google/uuid"
	"github.com/hashicorp/consul/api"
	"hotel-app/common/nacos"
)

func Consul() {
	nac := nacos.NacosConfig
	client, err := api.NewClient(&api.Config{Address: fmt.Sprintf("%s:%d", nac.Consul.Host, nac.Consul.Port)})
	if err != nil {
		return
	}
	id := uuid.New().String()
	err = client.Agent().ServiceRegister(&api.AgentServiceRegistration{
		ID:      id,
		Name:    nac.Consul.Name,
		Tags:    []string{"GRPC"},
		Port:    nac.Grpc.Port,
		Address: nac.Grpc.Host,
		Check: &api.AgentServiceCheck{
			Interval:                       "5s",
			Timeout:                        "5s",
			GRPC:                           fmt.Sprintf("%s:%d", nac.Grpc.Host, nac.Grpc.Port),
			DeregisterCriticalServiceAfter: "30s",
		},
	})
	if err != nil {
		return
	}

}
